package com.yunwaikeji.gy_tool_library.set;

import android.annotation.SuppressLint;
import android.view.View;

import com.yunwaikeji.gy_tool_library.interface1.GYViewSetSetInterface;
import com.yunwaikeji.gy_tool_library.utils.display.GYDisplayUtils;
import com.yunwaikeji.gy_tool_library.utils.GYViewUtils;
import com.yunwaikeji.gy_tool_library.info.GYBaseInfo;

public class GYViewSetSet<V extends View, VS extends GYViewSetSet<V, VS>> implements GYViewSetSetInterface<V, VS> {
    public View view;
    public V v;
    public VS vs;

    public GYViewSetSet(View view) {
        this.view = view;
        v = (V) view;
        vs = (VS) this;
    }

    @Override
    public VS setSizePx(int widthPx, int heightPx, float weight) {
        GYViewUtils.setSize().setSizePx(view, widthPx, heightPx, weight);
        return vs;
    }

    @Override
    public VS setSizeDp(int widthDp, int heightDp, float weight) {
        GYViewUtils.setSize().setSizeDp(view, widthDp, heightDp, weight);
        return vs;
    }

    @Override
    public VS setSizePx(int widthPx, int heightPx) {
        GYViewUtils.setSize().setSizePx(view, widthPx, heightPx);
        return vs;
    }

    @Override
    public VS setSizeDp(int widthDp, int heightDp) {
        GYViewUtils.setSize().setSizeDp(view, widthDp, heightDp);
        return vs;
    }

    @Override
    public VS setWidthPx(int widthPx) {
        GYViewUtils.setSize().setSizePx(view, widthPx, GYBaseInfo.UNCHANGED);
        return vs;
    }

    @Override
    public VS setWidthDp(int widthDp) {
        GYViewUtils.setSize().setSizeDp(view, widthDp, GYBaseInfo.UNCHANGED);
        return vs;
    }

    @Override
    public VS setHeightPx(int heightPx) {
        GYViewUtils.setSize().setSizePx(view, GYBaseInfo.UNCHANGED, heightPx);
        return vs;
    }

    @Override
    public VS setHeightDp(int heightDp) {
        GYViewUtils.setSize().setSizeDp(view, GYBaseInfo.UNCHANGED, heightDp);
        return vs;
    }

    @Override
    public VS setWeight(float weight) {
        GYViewUtils.setSize().setSizePx(view, GYBaseInfo.UNCHANGED, GYBaseInfo.UNCHANGED, weight);
        return vs;
    }

    @Override
    public float getWeight() {
        return GYViewUtils.setSize().getWeight(view);
    }

    @Override
    public int getWidthPx() {
        return GYViewUtils.setSize().getWidthPx(view);
    }

    @Override
    public int getHeightPx() {
        return GYViewUtils.setSize().getHeightPx(view);
    }

    @Override
    public VS setMarginPx(int leftPx, int topPx, int rightPx, int bottomPx) {
        GYViewUtils.setMargin().setMarginPx(view, leftPx, topPx, rightPx, bottomPx);
        return vs;
    }

    @Override
    public VS setMarginDp(int leftDp, int topDp, int rightDp, int bottomDp) {
        GYViewUtils.setMargin().setMarginDp(view, leftDp, topDp, rightDp, bottomDp);
        return vs;
    }

    @Override
    public VS setPaddingPx(int leftPx, int topPx, int rightPx, int bottomPx) {
        view.setPadding(leftPx, topPx, rightPx, bottomPx);
        return vs;
    }

    @Override
    public VS setPaddingDp(int leftDp, int topDp, int rightDp, int bottomDp) {
        view.setPadding(GYDisplayUtils.dp2px(view.getContext(), leftDp), GYDisplayUtils.dp2px(view.getContext(), topDp), GYDisplayUtils.dp2px(view.getContext(), rightDp), GYDisplayUtils.dp2px(view.getContext(), bottomDp));
        return vs;
    }

    @Override
    public VS setVisibility(int visibility) {
        view.setVisibility(visibility);
        return vs;
    }

    @Override
    public VS setClickable(boolean clickable) {
        view.setClickable(clickable);
        return vs;
    }

    @Override
    public VS setOnClickListener(View.OnClickListener onClickListener) {
        view.setOnClickListener(onClickListener);
        return vs;
    }

    @Override
    public VS setOnLongClickListener(View.OnLongClickListener onLongClickListener) {
        view.setOnLongClickListener(onLongClickListener);
        return vs;
    }

    @SuppressLint("NewApi")
    @Override
    public VS setOnContextClickListener(View.OnContextClickListener onContextClickListener) {
        view.setOnContextClickListener(onContextClickListener);
        return vs;
    }

    @Override
    public V toView() {
        return v;
    }

    @Override
    public VS toViewSet() {
        return vs;
    }
}
